from datetime import datetime
from app.extensions import db
from datetime import datetime
class Task(db.Model):
    """任务表模型"""
    __tablename__ = 'task'
    
    task_id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='任务唯一标识')
    plan_date = db.Column(db.Date, nullable=False, comment='计划日期')
    task_type = db.Column(db.Enum('每日', '复习', name='task_types'), 
                         nullable=False, comment='任务类型')
    status = db.Column(db.Boolean, default=False, nullable=False, comment='完成状态')
    review_stage = db.Column(db.Integer, nullable=False, comment='复习阶段序号')
    
    # 逻辑外键字段
    student_id = db.Column(db.Integer, db.ForeignKey('student.student_id'), 
                         nullable=False, comment='学生ID')
    content_id = db.Column(db.Integer, db.ForeignKey('content.content_id'), 
                          nullable=False, comment='内容ID')
    def to_dict(self,date_format='%Y-%m-%d'):
        return {
            'task_id': self.task_id,
            'plan_date': self.plan_date.strftime(date_format),
            'task_type': self.task_type,
            'status': self.status,
            'review_stage': self.review_stage,
            'student_id': self.student_id,
            'content_id': self.content_id,
        }
    def __repr__(self):
        return f'<Task {self.task_id} ({self.task_type})>'